home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Format / rfc1148 / RFCtoP2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  30.4 KB  |  1,312 lines

  1. /* RFCtoP2.c : 1138 encoding 822 -> P2 for headers */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Format/rfc1148/RCS/RFCtoP2.c,v 6.0 1991/12/18 20:20:34 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Format/rfc1148/RCS/RFCtoP2.c,v 6.0 1991/12/18 20:20:34 jpo Rel $
  9.  *
  10.  * $Log: RFCtoP2.c,v $
  11.  * Revision 6.0  1991/12/18  20:20:34  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "head.h"
  19. #include "util.h"
  20. #include "IOB-types.h"
  21. #include "rfc-hdr.h"
  22. #include "ap.h"
  23. #include "or.h"
  24. #include "oids.h"
  25. #include "charset.h"
  26. #include "chan.h"
  27.  
  28. static FILE *fp_P2_out;
  29. static FILE *fp_rfc_in;
  30. static FILE *fp_P2_ext;
  31. static char P2_ext [MAXPATHLENGTH];
  32. static CHAR8U    *asctot61();
  33. static struct type_IOB_Heading *head;
  34. static char first_hdr = TRUE;
  35. static int comments_started = FALSE;
  36.  
  37. extern time_t time();
  38. extern struct type_IOB_ORName    *orn2orname();
  39.  
  40. RFCtoP2 (rfc_in, P2_out, P2_ext_out, ep, x40084)
  41. char *rfc_in;
  42. char *P2_out;
  43. char *P2_ext_out;
  44. char    **ep;
  45. int    x40084;
  46. {
  47.     PE      pe;
  48.     PS      ps;
  49.     int     retval;
  50.     char    buf[BUFSIZ];
  51.  
  52.     first_hdr = TRUE;
  53.     comments_started = FALSE;
  54.     if (P2_ext_out)
  55.         strcpy (P2_ext, P2_ext_out);
  56.     else
  57.         P2_ext[0] = '\0';
  58.  
  59.     head = (struct type_IOB_Heading *)
  60.         calloc (1, sizeof (struct type_IOB_Heading));
  61.  
  62.     if ( head ==  (struct type_IOB_Heading *) NOTOK)
  63.  
  64.     {
  65.         PP_LOG (LLOG_EXCEPTIONS, ("RFCtoP2 - malloc failed"));
  66.         return NOTOK;
  67.     }                       /* allocate h, so that we can free */
  68.                 /* cleanly at the end of all this */
  69.  
  70.     if (P2_out == NULLCP)
  71.         fp_P2_out = stdout;
  72.  
  73.     else if ((fp_P2_out = fopen (P2_out, "w")) == NULL )
  74.     {
  75.         PP_SLOG (LLOG_EXCEPTIONS, P2_out,
  76.              ("Can't open file"));
  77.         (void) sprintf (buf,
  78.                 "Unable to open output file '%s'",
  79.                 P2_out);
  80.         *ep = strdup(buf);
  81.         return NOTOK;
  82.     }
  83.  
  84.     if (rfc_in == NULLCP)
  85.         fp_rfc_in = stdin;
  86.     else if ((fp_rfc_in = fopen (rfc_in, "r")) == NULL )
  87.     {
  88.         PP_SLOG (LLOG_EXCEPTIONS, rfc_in,
  89.              ("Can't open file"));
  90.         (void) sprintf (buf,
  91.                 "Unable to open input file '%s'",
  92.                 rfc_in);
  93.         *ep = strdup(buf);
  94.         fclose (fp_P2_out);
  95.         return NOTOK;
  96.     }
  97.  
  98.  
  99.  
  100.     if (((ps = ps_alloc (std_open)) == NULLPS) ||
  101.         (std_setup (ps, fp_P2_out) == NOTOK))
  102.     {
  103.         PP_LOG (LLOG_EXCEPTIONS, ("RFC822toP2() failed to setup PS"));
  104.         *ep = strdup("Failed to setup PS");
  105.         retval = NOTOK;
  106.         goto cleanup;
  107.     }
  108.  
  109.  
  110.             /* set defaults */
  111.  
  112.     head -> importance = (struct type_IOB_ImportanceField *) calloc (1, sizeof(struct type_IOB_ImportanceField));
  113.     head -> importance -> parm = int_IOB_ImportanceField_normal;
  114.  
  115.     if (build_hdr (x40084, ep) == NOTOK)
  116.     {
  117.         PP_LOG (LLOG_EXCEPTIONS, ("build_hdr blew it"));
  118.         retval = NOTOK;
  119.         goto cleanup;
  120.     }
  121.  
  122.     PY_pepy[0] = 0;
  123.  
  124.     if (encode_IOB_Heading (&pe, 0, 0, NULLCP, head) != OK)
  125.     {
  126.         PP_OPER (NULLCP, 
  127.              ("RFCtoP2() failed to encode header [%s]", PY_pepy));
  128.         (void) sprintf (buf,
  129.                 "Unable to encode p2 hdr ['%s']", 
  130.                 PY_pepy);
  131.         *ep = strdup(buf);
  132.         retval = NOTOK;
  133.         goto cleanup;
  134.     }
  135.  
  136.     if (PY_pepy[0] != 0)
  137.         PP_LOG(LLOG_EXCEPTIONS,
  138.                ("encode_IOB_Heading non-fatal failure [%s]",PY_pepy));
  139.  
  140.     if (pe2ps (ps, pe) == NOTOK)
  141.     {
  142.         PP_LOG (LLOG_EXCEPTIONS, ("RFCtoP2 failed to write heading"));
  143.         *ep = strdup("Failed to write header");
  144.         pe_free (pe);
  145.         retval = NOTOK;
  146.         goto cleanup;
  147.     }
  148.  
  149.     retval = OK;
  150.  
  151. cleanup:
  152.     ps_free (ps);
  153.     fclose (fp_P2_out);
  154.     fclose (fp_rfc_in);
  155.     if (fp_P2_ext != NULL)
  156.         fclose (fp_P2_ext);
  157.     free_IOB_Heading (head);
  158.     return retval;
  159. }
  160.  
  161. /*   */
  162.  
  163. build_hdr(x40084, ep)
  164. int    x40084;
  165. char    **ep;
  166. {
  167.     char    *field, *key;
  168.     struct type_IOB_RecipientSequence    *from = NULL;
  169.     struct type_IOB_RecipientSequence    *temp;
  170.     struct type_IOB_ORDescriptorSequence    *ix, *tail = (struct type_IOB_ORDescriptorSequence *) 0;
  171.     struct type_IOB_RFC822FieldList        *hdr_extns = NULL;
  172.     char    buf[BUFSIZ];
  173.  
  174.     while (TRUE) {
  175.         switch (get_hdr (&key, &field)) {
  176.             case HDR_EOH:
  177.             PP_DBG (("HDR_EOH"));
  178.             break;
  179.  
  180.             case HDR_ERROR:
  181.             PP_LOG (LLOG_EXCEPTIONS,
  182.                 ("Error reading header"));
  183.             *ep = strdup("Error reading header");
  184.             return NOTOK;
  185.  
  186.             case HDR_ILLEGAL:
  187.             PP_LOG (LLOG_EXCEPTIONS,
  188.                 ("Erroneous header '%s' '%s'", key, field));
  189.             (void) sprintf (buf,
  190.                        "Erroneous header '%s' '%s'",
  191.                        key, field);
  192.             *ep = strdup(buf);
  193.             return NOTOK;
  194.  
  195.             case HDR_IGNORE:
  196.             PP_DBG (("Ignoring header'%s'", key));
  197.             continue;
  198.  
  199.             case HDR_COMMENT:
  200.             if (hdr_comment (key, field, ep, x40084) != OK)
  201.                 return NOTOK;
  202.             continue;
  203.             
  204.             case HDR_MID:
  205.             if (hdr_mid (field, &(head -> this__IPM)) != OK)
  206.                 PP_DBG (("Bad message id '%s'", field));
  207.             continue;
  208.  
  209.             case HDR_FROM:
  210.             if (hdr_recip_set (field, &from, x40084) != OK)
  211.                 PP_DBG (("Bad From '%s'", field));
  212.             continue;
  213.  
  214.             case HDR_SENDER:
  215.             if (hdr_ordesc (field, &head -> originator, x40084) != OK)
  216.                 PP_DBG (("Bad Sender '%s'", field));
  217.             continue;
  218.  
  219.             case HDR_REPLY_BY:
  220.             if (hdr_reply_by (field, &(head -> reply__time)) != OK)
  221.                 PP_DBG (("Bad reply date '%s'", field));
  222.             continue;
  223.  
  224.             case HDR_REPLY_TO:
  225.             if (hdr_ordesc_seq (field, 
  226.                         &(head -> reply__recipients),
  227.                         x40084) != OK)
  228.                 PP_DBG (("Bad replied to '%s'", field));
  229.             continue;
  230.             
  231.             case HDR_IMPORTANCE:
  232.             if (hdr_importance (field,
  233.                         &(head->importance->parm)) != OK)
  234.                 PP_DBG (("Bad importance '%s'", field));
  235.             continue;
  236.  
  237.             case HDR_SENSITIVITY:
  238.             if (hdr_sensitivity (field,
  239.                          &(head->sensitivity)) != OK)
  240.                 PP_DBG (("Bad sensitivity '%s'", field));
  241.             continue;
  242.  
  243.             case HDR_AUTOFORWARDED:
  244.             if (hdr_autoforwarded (field,
  245.                            &(head->auto__forwarded)) != OK)
  246.                 PP_DBG(("Bad autoforwarded '%s'", field));
  247.             continue;
  248.  
  249.             case HDR_TO:
  250.             if (hdr_recip_set (field, 
  251.                        &(head -> primary__recipients),
  252.                        x40084) != OK)
  253.                 PP_DBG (("Bad to '%s'", field));
  254.             continue;
  255.  
  256.             case HDR_CC:
  257.             if (hdr_recip_set (field, 
  258.                        &(head -> copy__recipients),
  259.                        x40084) != OK)
  260.                 PP_DBG (("Bad cc '%s'", field));
  261.             continue;
  262.  
  263.             case HDR_BCC:
  264.             if (hdr_recip_set (field, 
  265.                        &(head -> blind__copy__recipients),
  266.                        x40084) != OK)
  267.                 PP_DBG (("Bad bcc '%s'", field));
  268.             continue;
  269.  
  270.             case HDR_IN_REPLY_TO:
  271.             if (hdr_reply_to (field, 
  272.                       &(head -> replied__to__IPM),
  273.                       &(head -> related__IPMs)) != OK)
  274.                 PP_DBG (("Bad in reply to '%s'", field));
  275.             continue;
  276.  
  277.             case HDR_OBSOLETES:
  278.             if (hdr_mid_seq (field, &(head -> obsoleted__IPMs)) != OK)
  279.                 PP_DBG (("Bad obsoletes '%s'", field));
  280.             continue;
  281.  
  282.             case HDR_REFERENCES:
  283.             if (hdr_mid_seq (field, &(head -> related__IPMs)) != OK)
  284.                 PP_DBG (("Bad references '%s'", field));
  285.             continue;
  286.  
  287.             case HDR_EXTENSIONS:
  288.             if (x40084 == TRUE) {
  289.                 if (hdr_comment (key, field, ep, x40084) != OK)
  290.                     return NOTOK;
  291.             } else if (hdr_extension (key, field, 
  292.                           &(hdr_extns)) != OK)
  293.                 PP_DBG (("Bad extension '%s'", field));
  294.             continue;
  295.  
  296.             case HDR_INCOMPLETE_COPY:
  297.             if (x40084 == TRUE) {
  298.                 PP_LOG(LLOG_EXCEPTIONS,
  299.                        ("Unable to convert to p2 (84) '%s %s'",
  300.                     key, field));
  301.                 (void) sprintf (buf,
  302.                            "Unable to convert to p2 (84) '%s %s'",
  303.                            key, field);
  304.                 *ep = strdup(buf);
  305.                 return NOTOK;
  306.             }
  307.             if (hdr_incomplete_copy (&(head -> extensions)) != OK)
  308.                 PP_DBG (("Bad incomplete_copy '%s'", field));
  309.             continue;
  310.  
  311.             case HDR_LANGUAGE:
  312.             if (x40084 == TRUE) {
  313.                 PP_LOG(LLOG_EXCEPTIONS,
  314.                        ("Unable to convert to p2 (84) '%s %s'",
  315.                     key, field));
  316.                 (void) sprintf (buf,
  317.                            "Unable to convert to p2 (84) '%s %s'",
  318.                            key, field);
  319.                 *ep = strdup(buf);
  320.                 return NOTOK;
  321.             }
  322.             if (hdr_language (field, &(head -> extensions)) != OK)
  323.                 PP_DBG (("Bad language '%s'", field));
  324.             continue;
  325.  
  326.             case HDR_SUBJECT:
  327.             if (hdr_subject (field, &(head -> subject)) != OK)
  328.                 PP_DBG (("Bad subject '%s'", field));
  329.             continue;
  330.  
  331.             case HDR_EXPIRY_DATE:
  332.             if (hdr_expiry_date (field, &(head-> expiry__time)) != OK)
  333.                 PP_DBG(("Bad expiry date '%s'", field));
  334.             continue;
  335.  
  336.             default:
  337.             PP_LOG (LLOG_EXCEPTIONS,
  338.                 ("Unexpected Header Type"));
  339.             *ep = strdup("Unexpected Header Type");
  340.             return NOTOK;
  341.         }
  342.         break;
  343.     }
  344.  
  345.     if (hdr_extns != (struct type_IOB_RFC822FieldList *) NULL) {
  346.         /* header extensions */
  347.         struct type_IOB_ExtensionsField *temp = (struct type_IOB_ExtensionsField *)
  348.             calloc (1, sizeof (struct type_IOB_ExtensionsField));
  349.         temp -> HeadingExtension = (struct type_IOB_HeadingExtension *)
  350.             calloc (1, sizeof (struct type_IOB_HeadingExtension));
  351.         temp -> HeadingExtension -> type = oid_cpy(str2oid(id_rfc_822_field_list));
  352.         PY_pepy[0] = 0;
  353.         if (encode_IOB_RFC822FieldList(&(temp -> HeadingExtension -> value),
  354.                            0, 0, NULLCP, hdr_extns)) {
  355.             PP_OPER (NULLCP,
  356.                  ("failed to encode rfc822 FieldList extension [%s]",
  357.                   PY_pepy));
  358.             oid_free ((char *) temp -> HeadingExtension -> type);
  359.             free ((char *) temp -> HeadingExtension);
  360.             free ((char *) temp);
  361.             return NOTOK;
  362.         } else
  363.             free_IOB_RFC822FieldList(hdr_extns);
  364.         temp -> next = head->extensions;
  365.         head->extensions = temp;
  366.     }
  367.  
  368.         
  369.     if (head -> originator == (struct type_IOB_ORDescriptor *) 0) {
  370.         if (from != (struct type_IOB_RecipientSequence *) 0) {
  371.             head -> originator = from -> RecipientSpecifier -> recipient;
  372.             free ((char *) from -> RecipientSpecifier);
  373.             temp = from;
  374.             from = from -> next;
  375.             free ((char *) temp);
  376.         }
  377.     }
  378.     
  379.     /* convert RecipientSequence to ORDescriptorSequence */
  380.     while (from != (struct type_IOB_RecipientSequence *) 0) {
  381.         ix = (struct type_IOB_ORDescriptorSequence *) calloc (1,
  382.                                      sizeof(struct type_IOB_ORDescriptorSequence));
  383.         ix -> ORDescriptor = from -> RecipientSpecifier -> recipient;
  384.         free((char *) from -> RecipientSpecifier);
  385.         temp=from;
  386.         from=from->next;
  387.         free((char *) temp);
  388.         if (head -> authorizing__users == (struct type_IOB_ORDescriptorSequence *) 0) 
  389.             head -> authorizing__users = tail = ix;
  390.         else {
  391.             tail -> next = ix;
  392.             tail = ix;
  393.         }
  394.     }
  395.     if (head -> this__IPM == NULL)
  396.         gen_mid (&(head -> this__IPM));
  397.     
  398.     return OK;
  399. }
  400.  
  401. /*   */
  402.  
  403. hdr_comment (key, field, ep, x40084)
  404. char    *key,
  405.     *field,
  406.     **ep;
  407. int    x40084;
  408. {
  409.     char    buf[BUFSIZ];
  410.     PP_DBG (("hdr_comments '%s'", field));
  411.     if (P2_ext == NULLCP || P2_ext[0] == '\0')
  412.         return OK;
  413.     
  414.     if (!comments_started) {
  415.         comments_started = TRUE;
  416.         if ((fp_P2_ext = fopen (P2_ext, "w")) == NULL) {
  417.             PP_SLOG (LLOG_EXCEPTIONS, P2_ext,
  418.                  ("Can't open file"));
  419.             (void) sprintf (buf,
  420.                     "Failed to open extension file '%s'",
  421.                     P2_ext);
  422.             *ep = strdup(buf);
  423.             return NOTOK;
  424.         }
  425.         if (TRUE == x40084)
  426.             fputs("RFC-822-HEADERS:\n", fp_P2_ext);
  427.         else
  428.             fputs("Comments:\n", fp_P2_ext);
  429.     }
  430.     field_tidy(key);
  431.     fputs (key, fp_P2_ext);
  432.     fputs (": ", fp_P2_ext);
  433.     field_tidy(field);
  434.     fputs (field, fp_P2_ext);
  435.     fputs ("\n", fp_P2_ext);
  436.     return OK;
  437. }
  438.  
  439. hdr_mid_seq (field, seq_ptr)
  440. char    *field;
  441. struct type_IOB_IPMIdentifierSequence    **seq_ptr;
  442. {
  443.     char    *p, *q;
  444.     struct type_IOB_IPMIdentifierSequence    *temp, *ix;
  445.     
  446.     field_tidy (field);
  447.     p = q = field;
  448.     while (q != NULLCP)
  449.     {
  450.         if ((q = index (p, ',')) != NULLCP)
  451.             *q++ = '\0';
  452.         temp = (struct type_IOB_IPMIdentifierSequence *)
  453.             calloc (1, sizeof (struct type_IOB_IPMIdentifierSequence));
  454.         if (hdr_mid (p, &(temp -> IPMIdentifier)) != OK) {
  455.             free ((char *) temp);
  456.             return NOTOK;
  457.         }
  458.         p = q;
  459.         if (*seq_ptr == NULL)
  460.             *seq_ptr = temp;
  461.         else {
  462.             ix = *seq_ptr;
  463.             while (ix -> next != NULL) ix = ix -> next;
  464.             ix -> next = temp;
  465.         }
  466.     }
  467.     return OK;
  468. }
  469.         
  470. hdr_mid (field, mid_ptr)
  471. char    *field;
  472. struct type_IOB_IPMIdentifier    **mid_ptr;
  473. {
  474.     /* see rfc 1138 4.7.3.3 */
  475.     char *midstring, *cp;
  476.     char    ps[BUFSIZ];
  477.     ORName    orn;
  478.     AP_ptr    ap, local, domain;
  479.  
  480.     if ((midstring = index (field, '<')) == NULLCP
  481.         || (cp = rindex (field, '>')) == NULLCP)
  482.         return NOTOK;
  483.     *cp = '\0';
  484.     midstring++;
  485.  
  486.     if (ap_s2p (midstring, &ap, (AP_ptr *) 0, (AP_ptr *) 0, &local,
  487.             &domain, (AP_ptr *) 0) == (char *) NOTOK)
  488.     {
  489.         PP_LOG (LLOG_EXCEPTIONS,
  490.             ( "Illegal Message ID '%s'", midstring));
  491.         *mid_ptr = NULL;
  492.         return NOTOK;
  493.     }
  494.  
  495.     *mid_ptr = (struct type_IOB_IPMIdentifier *) 
  496.         calloc (1, sizeof (struct type_IOB_IPMIdentifier));
  497.  
  498.     if (domain != NULLAP && local != NULLAP
  499.         && lexequ (domain -> ap_obvalue, "MHS") == 0
  500.         && (cp = index (local -> ap_obvalue, '*')) != NULLCP) {
  501.         /* x.400 generated */
  502.  
  503.         if (cp != local -> ap_obvalue) {
  504.             *cp++ = '\0';
  505.             (*mid_ptr)-> user__relative__identifier = 
  506.                 str2qb (local -> ap_obvalue,
  507.                     strlen (local -> ap_obvalue),
  508.                     1);
  509.         }
  510.         if (*cp == '\0')
  511.             return OK;
  512.  
  513.         orn.on_or = or_std2or(cp);
  514.         orn.on_dn = NULL;
  515.  
  516.         ap_1delete(ap);
  517.         ap_free(ap);
  518.  
  519.         if (orn.on_or != NULLOR) {
  520.             (*mid_ptr) -> user = orn2orname(&orn);
  521.             or_free(orn.on_or);
  522.         }
  523.  
  524.         return OK;
  525.     } else {
  526.         or_asc2ps(midstring, ps);
  527.         (*mid_ptr) -> user__relative__identifier = str2qb (ps,    
  528.                                    strlen(ps),
  529.                                    1);
  530.         return OK;
  531.     }
  532. }
  533.  
  534. get_comments (buf, addr)
  535. char *buf;
  536. AP_ptr addr;
  537. {
  538.     AP_ptr ap;
  539.  
  540.     buf [0] = '\0';
  541.     ap = addr;
  542.     while (TRUE)
  543.     {
  544.         if (ap -> ap_obtype == AP_COMMENT)
  545.         {
  546.             strcat (buf, " (");
  547.             strcat (buf, ap -> ap_obvalue);
  548.             strcat (buf, ")");
  549.         }
  550.         if (ap -> ap_next == NULLAP
  551.             || ap -> ap_next -> ap_ptrtype == AP_PTR_NXT)
  552.             break;
  553.         ap = ap -> ap_next;
  554.     }
  555.     PP_DBG (("Comment '%s'", buf));
  556.     return OK;
  557. }
  558. PE or2pe();
  559.  
  560. #ifdef notdef
  561.  
  562. static int ORstring2pe (orstring, pe)
  563. char *orstring;
  564. PE *pe;
  565. {
  566.     OR_ptr or;
  567.     *pe = NULLPE;
  568.  
  569.     if (or_rfc2or (orstring, &or) == NOTOK)
  570.     {
  571.         PP_DBG (("Failed to parse '%s'", orstring));
  572.         return NOTOK;
  573.     }
  574.  
  575.     or = or_default (or);
  576.  
  577.     if ((*pe = or2pe (or)) == NULLPE)
  578.     {
  579.         PP_DBG (("Failed to decode OR_Ptr '%s'", orstring));
  580.         return NOTOK;
  581.     }
  582.     or_free (or);
  583.     return OK;
  584. }
  585. #endif
  586.  
  587. get_ordesc (cpp, or_desc_ptr, group_ptr, x40084)
  588. char    **cpp;
  589. struct type_IOB_ORDescriptor    **or_desc_ptr, **group_ptr;
  590. int    x40084;
  591. {
  592.     /* see rfc 1138 4.7.1 */
  593.     AP_ptr    ap, group, name, local, domain, route, ix;
  594.     char    comment[BUFSIZ], freeform[BUFSIZ], buf[BUFSIZ];
  595.     char    *addr;
  596.     ORName    orn;
  597.  
  598.     if (*cpp == NULLCP || **cpp == '\0')
  599.         return OK;
  600.  
  601.     PP_DBG (("get_ordesc ('%s')", *cpp));
  602.  
  603.     if ((*cpp = ap_s2p (*cpp, &ap,
  604.                 &group, &name, &local,
  605.                 &domain, &route)) == (char *) NOTOK
  606.         || *cpp == (char *) DONE)
  607.         return NOTOK;
  608.  
  609.     *or_desc_ptr = (struct type_IOB_ORDescriptor *) 
  610.         calloc (1, sizeof (struct type_IOB_ORDescriptor));
  611.  
  612.     addr = ap_p2s_nc (NULLAP, NULLAP, local, domain, route);
  613.     
  614.     if (addr == NULLCP || *addr == '\0') {
  615.         orn.on_or = NULLOR;
  616.         orn.on_dn = NULL;
  617.     } else {
  618.         if (or_rfc2or(addr, &(orn.on_or)) == NOTOK) {
  619.             PP_DBG (("Failed to encode '%s'", addr));
  620.             free (addr);
  621.             return NOTOK;
  622.         } else 
  623.             /* maybe try to regain from comments ? */
  624.             orn.on_dn = NULL;
  625.  
  626.         if (x40084 == TRUE) 
  627.             or_downgrade(&(orn.on_or));
  628.     }
  629.  
  630.     if (addr)
  631.         free(addr);
  632.  
  633.     if (orn.on_or != NULLOR) {
  634.         (*or_desc_ptr) -> formal__name = (struct type_IOB_ORName *)
  635.             calloc (1, sizeof (struct type_IOB_ORName));
  636.         (*or_desc_ptr) -> formal__name = orn2orname(&orn);
  637.         or_free (orn.on_or);
  638.     }
  639.     
  640.     get_comments (comment, ap);
  641.  
  642.     freeform [0] = '\0';
  643.     if (name != NULLAP) {
  644.         ix = name;
  645.         while (ix != NULLAP &&
  646.                (ix -> ap_obtype == AP_COMMENT ||
  647.             ix -> ap_obtype == AP_PERSON_END ||
  648.             ix -> ap_obtype == AP_PERSON_NAME ||
  649.             ix -> ap_obtype == AP_PERSON_START)) {
  650.             if (ix -> ap_obtype != AP_COMMENT &&
  651.                 ix -> ap_obvalue != NULLCP) {
  652.                 if (freeform[0] != '\0')
  653.                     strcat (freeform, " ");
  654.                 strcat (freeform, ix -> ap_obvalue);
  655.             }
  656.             ix = ix -> ap_next;
  657.         }
  658.     }
  659.  
  660.     strcat (freeform, comment);
  661.     
  662.     if (freeform[0] != '\0') {
  663.         /* do ascii -> t.61 */
  664.         CHAR8U    *t61str;
  665.         int    len;
  666.  
  667.         strcpy (buf, freeform);
  668.         
  669.         if ((t61str = asctot61 ((CHAR8U *) buf, &len)) 
  670.             != (CHAR8U *) NULL) {
  671.             (*or_desc_ptr) -> free__form__name = 
  672.                 str2qb (t61str, strlen((char *) t61str), 1);
  673.             free(t61str);
  674.         } else
  675.             (*or_desc_ptr) -> free__form__name = 
  676.                 str2qb (buf, strlen(buf), 1);
  677.     }
  678.  
  679.     if (group != NULLAP) {
  680.         freeform[0] = '\0';
  681.         ix = group;
  682.         while (ix != NULLAP &&
  683.                (ix -> ap_obtype == AP_COMMENT ||
  684.             ix -> ap_obtype == AP_GROUP_END ||
  685.             ix -> ap_obtype == AP_GROUP_NAME ||
  686.             ix -> ap_obtype == AP_GROUP_START)) {
  687.             if (ix -> ap_obtype != AP_COMMENT
  688.                 && ix -> ap_obvalue != NULLCP) {
  689.                 if (freeform[0] != '\0')
  690.                     strcat (freeform, " ");
  691.                 strcat (freeform, ix -> ap_obvalue);
  692.             }
  693.             ix = ix -> ap_next;
  694.         }
  695.         if (freeform[0] != '\0') {
  696.             CHAR8U    *t61str;
  697.             int    len;
  698.  
  699.             *group_ptr = (struct type_IOB_ORDescriptor *)
  700.                 calloc (1, sizeof (struct type_IOB_ORDescriptor));
  701.             /* do ascii -> t.61 conversion */
  702.             strcpy (buf, freeform);
  703.             if ((t61str = asctot61 ((CHAR8U *) buf, &len)) 
  704.                 != (CHAR8U *) NULL) {
  705.                 (*group_ptr) -> free__form__name = 
  706.                     str2qb (t61str, strlen((char *)t61str), 1);
  707.                 free(t61str);
  708.             } else
  709.                 (*group_ptr) -> free__form__name = 
  710.                     str2qb (buf, strlen(buf), 1);
  711.         }
  712.     } else
  713.         *group_ptr = NULL;
  714.     ap_1delete(ap);
  715.     ap_free (ap);
  716.     return OK;
  717. }
  718.  
  719. hdr_ordesc (field, or_desc_ptr, x40084)
  720. char    *field;
  721. struct type_IOB_ORDescriptor    **or_desc_ptr;
  722. int    x40084;
  723. {
  724.     struct type_IOB_ORDescriptor    *gptr;
  725.     char    *cp;
  726.     
  727.     field_tidy (field);
  728.     cp = field;
  729.     if (cp == NULLCP || *cp == '\0')
  730.         return OK;
  731.  
  732.     if (get_ordesc (&cp, or_desc_ptr, &gptr, x40084) != OK) {
  733.         PP_DBG(("Bad single OR desc '%s'", field));
  734.         return NOTOK;
  735.     }
  736.     return OK;
  737. }
  738.  
  739. hdr_ordesc_seq (field, or_desc_ptr, x40084)
  740. char    *field;
  741. struct type_IOB_ORDescriptorSequence    **or_desc_ptr;
  742. int    x40084;
  743. {
  744.     char    *cp;
  745.     struct type_IOB_ORDescriptorSequence    *temp, *ix;
  746.     struct type_IOB_ORDescriptor    *dptr, *gptr;
  747.  
  748.     field_tidy (field);
  749.     cp = field;
  750.     
  751.     if (cp == NULLCP || *cp == '\0')
  752.         return OK;
  753.     
  754.     while (get_ordesc (&cp, &dptr, &gptr, x40084) == OK) {
  755.         if (gptr != (struct type_IOB_ORDescriptor *) NULL) {
  756.             temp = (struct type_IOB_ORDescriptorSequence *)
  757.                 calloc (1, sizeof (struct type_IOB_ORDescriptorSequence));
  758.             temp -> ORDescriptor = gptr;
  759.             if (*or_desc_ptr == NULL)
  760.                 *or_desc_ptr = temp;
  761.             else {
  762.                 ix = *or_desc_ptr;
  763.                 while (ix -> next != NULL) ix = ix -> next;
  764.                 ix -> next = temp;
  765.             }
  766.         }
  767.         temp = (struct type_IOB_ORDescriptorSequence *)
  768.             calloc (1, sizeof (struct type_IOB_ORDescriptorSequence));
  769.         temp -> ORDescriptor = dptr;
  770.         if (*or_desc_ptr == NULL)
  771.             *or_desc_ptr = temp;
  772.         else {
  773.             ix = *or_desc_ptr;
  774.             while (ix -> next != NULL) ix = ix -> next;
  775.             ix -> next = temp;
  776.         }
  777.         if (cp == NULLCP || *cp == '\0')
  778.             return OK;
  779.     }
  780.     PP_DBG (("Bad address field '%s'", field));
  781.     return NOTOK;
  782. }
  783.  
  784. hdr_recip_set (field, or_recip_ptr, x40084)
  785. char    *field;
  786. struct type_IOB_RecipientSequence    **or_recip_ptr;
  787. int    x40084;
  788. {
  789.     /* see rfc 1138 4.7.1 */
  790.     struct type_IOB_RecipientSequence    *temp, *ix;
  791.     char    *cp;
  792.     struct type_IOB_ORDescriptor    *dptr, *gptr;
  793.  
  794.     field_tidy (field);
  795.     cp = field;
  796.  
  797.     if (cp == NULLCP || *cp == '\0')
  798.         return OK;
  799.     
  800.     while (get_ordesc (&cp, &dptr, &gptr, x40084) == OK) {
  801.         if (gptr != (struct type_IOB_ORDescriptor *) NULL) {
  802.             temp = (struct type_IOB_RecipientSequence *)
  803.                 calloc (1, sizeof (struct type_IOB_RecipientSequence));
  804.             temp -> RecipientSpecifier = (struct type_IOB_RecipientSpecifier *)
  805.                 calloc (1, sizeof(struct type_IOB_RecipientSpecifier));
  806.             temp -> RecipientSpecifier -> recipient = gptr;
  807.             /* defaults for other fields == 0 */
  808.             if (*or_recip_ptr == NULL)
  809.                 *or_recip_ptr = temp;
  810.             else {
  811.                 ix = *or_recip_ptr;
  812.                 while (ix -> next != NULL) ix = ix -> next;
  813.                 ix -> next = temp;
  814.             }
  815.         }
  816.         if (dptr != (struct type_IOB_ORDescriptor *) NULL
  817.             && (dptr->formal__name != (struct type_IOB_ORName *) NULL
  818.             || dptr->free__form__name != (struct type_IOB_FreeFormName *) NULL)) {
  819.             temp = (struct type_IOB_RecipientSequence *)
  820.                 calloc (1, sizeof (struct type_IOB_RecipientSequence));
  821.             temp -> RecipientSpecifier = (struct type_IOB_RecipientSpecifier *)
  822.                 calloc (1, sizeof(struct type_IOB_RecipientSpecifier));
  823.             temp -> RecipientSpecifier -> recipient = dptr;
  824.             /* defaults for other fields == 0 */
  825.             if (*or_recip_ptr == NULL)
  826.                 *or_recip_ptr = temp;
  827.             else {
  828.                 ix = *or_recip_ptr;
  829.                 while (ix -> next != NULL) ix = ix -> next;
  830.                 ix -> next = temp;
  831.             }
  832.         }
  833.         if (cp == NULLCP || *cp == '\0')
  834.             return OK;
  835.     }
  836.     PP_DBG (("Bad Address field '%s'", field));
  837.     return NOTOK;
  838. }
  839.  
  840. hdr_reply_to (field, replied_ptr, related_ptr)
  841. char    *field;
  842. struct type_IOB_IPMIdentifier    **replied_ptr;
  843. struct type_IOB_IPMIdentifierSequence    **related_ptr;
  844. {
  845.     char    *start, *end, savech;
  846.     struct type_IOB_IPMIdentifierSequence    *temp, *ix;
  847.     struct type_IOB_IPMIdentifier    *msgid;
  848.     
  849.     if ((start = index(field, '<')) == NULLCP)
  850.         /* no message id can't do anything */
  851.         return OK;
  852.     
  853.     while (*(start+1) != '\0' && *(start+1) == '<') start++;
  854.  
  855.     if ((end = index(start, '>')) == NULLCP)
  856.         /* incomplete msgid can't do anything */
  857.         return OK;
  858.     end++;
  859.     savech = *end;
  860.     *end = '\0';
  861.     if (hdr_mid (start, &msgid) != OK) 
  862.         return NOTOK;
  863.     *end = savech;
  864.  
  865.     if (*end == '\0'
  866.         || (start = index(end, '<')) == NULLCP) 
  867.         /* only one so put in replied_ptr */
  868.         *replied_ptr = msgid;
  869.     else {
  870.         /* more than one put in related_ptr */
  871.         temp = (struct type_IOB_IPMIdentifierSequence *)
  872.             calloc (1, sizeof(struct type_IOB_IPMIdentifierSequence));
  873.         temp -> IPMIdentifier = msgid;
  874.         
  875.         if (*related_ptr == NULL)
  876.             *related_ptr = temp;
  877.         else {
  878.             ix = *related_ptr;
  879.             while (ix -> next != NULL) ix = ix -> next;
  880.             ix -> next = temp;
  881.         }
  882.  
  883.         while (end != NULLCP && *end != '\0') {
  884.  
  885.             if ((start = index(end, '<')) == NULLCP)
  886.                 /* no message id can't do anything */
  887.                 return OK;
  888.             while (*(start+1) != '\0' && *(start+1) == '<') start++;
  889.             if ((end = index(start, '>')) == NULLCP)
  890.                 /* incomplete msgid can't do anything */
  891.                 return OK;
  892.             temp = (struct type_IOB_IPMIdentifierSequence *)
  893.                 calloc (1, sizeof(struct type_IOB_IPMIdentifierSequence));
  894.             end++;
  895.             savech = *end;
  896.             *end = '\0';
  897.             if (hdr_mid (start, &(temp -> IPMIdentifier)) != OK) {
  898.                 free(temp);
  899.                 return OK;
  900.             }
  901.             *end = savech;
  902.             if (*related_ptr == NULL)
  903.                 *related_ptr = temp;
  904.             else {
  905.                 ix = *related_ptr;
  906.                 while (ix -> next != NULL) ix = ix -> next;
  907.                 ix -> next = temp;
  908.             }
  909.             
  910.         }            
  911.     }
  912.     return OK;
  913. }
  914.  
  915. hdr_extension (key, field, extensionptr)
  916. char    *field, *key;
  917. struct type_IOB_RFC822FieldList    **extensionptr;
  918. {
  919.     char    buf[BUFSIZ];
  920.     struct type_IOB_RFC822FieldList *temp = (struct type_IOB_RFC822FieldList *)
  921.         calloc(1, sizeof(*temp));
  922.     struct type_IOB_RFC822Field     *hdr;
  923.     if (field[strlen(field)-1] == '\n')
  924.         field[strlen(field)-1] = '\0';
  925.     (void) sprintf (buf, "%s: %s", key, field);
  926.     temp->RFC822Field = str2qb (buf, strlen(buf), 1);
  927.     temp->next = *extensionptr;
  928.     *extensionptr = temp;
  929.     return OK;
  930. }
  931.  
  932. hdr_incomplete_copy (extensionptr)
  933. struct type_IOB_ExtensionsField    **extensionptr;
  934. {
  935.     struct type_IOB_ExtensionsField *temp = (struct type_IOB_ExtensionsField *)
  936.         calloc (1, sizeof (struct type_IOB_ExtensionsField));
  937.     temp -> HeadingExtension = (struct type_IOB_HeadingExtension *)
  938.         calloc (1, sizeof (struct type_IOB_HeadingExtension));
  939.  
  940.     PY_pepy[0] = 0;
  941.  
  942.     if (encode_IOB_IncompleteCopy (&(temp -> HeadingExtension -> value),
  943.                       0, 0, NULLCP, 
  944.                       (struct type_IOB_IncompleteCopy *) NULL) != OK)
  945.     {
  946.         PP_OPER (NULLCP,
  947.              ("failed to encode incomplete copy value [%s]",
  948.               PY_pepy));
  949.         free ((char *)temp -> HeadingExtension);
  950.         free ((char *)temp);
  951.         return NOTOK;
  952.     }
  953.  
  954.     temp -> HeadingExtension -> type = oid_cpy(str2oid(id_hex_incomplete_copy));
  955.     
  956.     temp -> next = *extensionptr;
  957.     *extensionptr = temp;
  958.     return OK;
  959. }
  960.     
  961. hdr_language (field, extensionptr)
  962. char    *field;
  963. struct type_IOB_ExtensionsField    **extensionptr;
  964. {
  965.     struct type_IOB_Languages    *lang = (struct type_IOB_Languages *)
  966.         calloc (1, sizeof (struct type_IOB_Languages));
  967.  
  968.     struct type_IOB_ExtensionsField *temp = (struct type_IOB_ExtensionsField *)
  969.         calloc (1, sizeof (struct type_IOB_ExtensionsField));
  970.  
  971.     temp -> HeadingExtension = (struct type_IOB_HeadingExtension *)
  972.         calloc (1, sizeof (struct type_IOB_HeadingExtension));
  973.  
  974.     while (isspace (*field)) field++;
  975.  
  976.     lang -> Language = str2qb(field, strlen(field), 1);
  977.  
  978.     PY_pepy[0] = 0;
  979.  
  980.     if (encode_IOB_Languages (&(temp -> HeadingExtension -> value),
  981.                  0,
  982.                  0,
  983.                  NULLCP,
  984.                  lang) != OK)
  985.     {
  986.         PP_OPER (NULLCP,
  987.              ("failed to encode language heading extension [%s]",
  988.               PY_pepy));
  989.         free ((char *)lang);
  990.         free ((char *) temp -> HeadingExtension);
  991.         free ((char *) temp);
  992.         return NOTOK;
  993.     }
  994.  
  995.     temp -> HeadingExtension -> type = oid_cpy(str2oid(id_hex_languages));
  996.  
  997.     temp -> next = *extensionptr;
  998.     *extensionptr = temp;
  999.  
  1000.     return OK;
  1001. }
  1002.  
  1003. static CHARSET    *ia5 = (CHARSET *) NULL;
  1004. static CHARSET    *t61 = (CHARSET *) NULL;
  1005.  
  1006. /* needed for odd behaviour of keld's code */
  1007. #define FUDGE 10
  1008.  
  1009. static CHAR8U *asctot61 (ia5str, plen)
  1010. CHAR8U    *ia5str;
  1011. int     *plen;
  1012. {
  1013.     CHAR8U    *t61str;
  1014.     
  1015.     if (ia5 == (CHARSET *) NULL)
  1016.         ia5 = getchset("CCITT_T.50.irv:1988", (INT16S) 29);
  1017.     if (t61 == (CHARSET *) NULL)
  1018.         t61 = getchset("T.61-8bit", (INT16S) 29);
  1019.  
  1020.     if (ia5 != (CHARSET *) NULL
  1021.         && t61 != (CHARSET *) NULL) {
  1022.         t61str = (CHAR8U *) malloc(sizeof(CHAR8U) * (strlen((char *)ia5str)+1));
  1023.         if ((*plen = strncnv (t61, ia5, 
  1024.                       t61str, ia5str, 
  1025.                       strlen((char *) ia5str), FALSE) >= 0))
  1026.             return t61str;
  1027.     } 
  1028.     return (CHAR8U *) NULL;
  1029. }
  1030.     
  1031. hdr_subject (field, subject_ptr)
  1032. char    *field;
  1033. struct type_IOB_SubjectField    **subject_ptr;
  1034. {
  1035.     CHAR8U    *t61str;
  1036.     int    len;
  1037.     while (isspace (*field)) field++;
  1038.     
  1039.     if (*field == '\0') {
  1040.         *subject_ptr = NULL;
  1041.         return OK;
  1042.     }
  1043.     if (*(field+strlen(field)-1) == '\n')
  1044.         *(field+strlen(field)-1) = '\0';
  1045.  
  1046.     if ((t61str = asctot61((CHAR8U *) field, &len)) != (CHAR8U *) NULL) {
  1047.         *subject_ptr = str2qb(t61str, strlen((char *)t61str), 1);
  1048.         free(t61str);
  1049.     } else
  1050.         *subject_ptr = str2qb (field, strlen(field), 1);
  1051.     return OK;
  1052. }
  1053.  
  1054. hdr_expiry_date(field, expiry)
  1055. char    *field;
  1056. struct qbuf **expiry;
  1057. {
  1058.     UTC    ut;
  1059.     char    *str;
  1060.     if (rfc2UTC (field, &ut) != OK)
  1061.         return NOTOK;
  1062.     str = utct2str(ut);
  1063.     *expiry = str2qb(str, strlen(str), 1);
  1064.     return OK;
  1065. }
  1066.  
  1067.  
  1068. hdr_reply_by(field, reply)
  1069. char    *field;
  1070. struct qbuf **reply;
  1071. {
  1072.     UTC    ut;
  1073.     char    *str;
  1074.     if (rfc2UTC (field, &ut) != OK)
  1075.         return NOTOK;
  1076.     str = utct2str(ut);
  1077.     *reply = str2qb(str, strlen(str), 1);
  1078.     return OK;
  1079. }
  1080.     
  1081.  
  1082. /*   */
  1083.  
  1084. static char *hdrbuf;
  1085. static int hdrbuflen;
  1086. static char linebuf [LINESIZE];
  1087.  
  1088. static CMD_TABLE hdr_list[] = {
  1089. "autoforwarded",    HDR_AUTOFORWARDED,
  1090. "bcc",          HDR_BCC,
  1091. "cc",           HDR_CC,
  1092. "comments",    HDR_COMMENT,
  1093. "content-identifier",    HDR_IGNORE,
  1094. "conversion",    HDR_IGNORE,
  1095. "conversion-with-loss",    HDR_IGNORE,
  1096. "date",         HDR_IGNORE,
  1097. "deferred-delivery",    HDR_IGNORE,
  1098. "discarded-x400-ipms-extensions", HDR_IGNORE,
  1099. "discarded-x400-mts-extensions", HDR_IGNORE,
  1100. "dl-expansion-history",    HDR_IGNORE,
  1101. "expiry-date",    HDR_EXPIRY_DATE,
  1102. "from",         HDR_FROM,
  1103. "generate-delivery-report",    HDR_IGNORE,
  1104. "importance",    HDR_IMPORTANCE,
  1105. "in-reply-to",  HDR_IN_REPLY_TO,
  1106. "incomplete-copy", HDR_INCOMPLETE_COPY,
  1107. "language",    HDR_LANGUAGE,
  1108. "latest-delivery-time",    HDR_IGNORE,
  1109. "message-id",   HDR_MID,
  1110. "message-type",    HDR_IGNORE,
  1111. "obsoletes",    HDR_OBSOLETES,
  1112. "original-encoded-information-types",    HDR_IGNORE,
  1113. "prevent-nondelivery-report",    HDR_IGNORE,
  1114. "priority",    HDR_IGNORE,
  1115. "received",     HDR_IGNORE,
  1116. "references",   HDR_REFERENCES,
  1117. "reply-by",    HDR_REPLY_BY,
  1118. "reply-to",     HDR_REPLY_TO,
  1119. "sender",       HDR_SENDER,
  1120. "sensitivity",    HDR_SENSITIVITY,
  1121. "subject",      HDR_SUBJECT,
  1122. "to",           HDR_TO,
  1123. "via",          HDR_IGNORE,
  1124. "x400-content-type",     HDR_IGNORE,
  1125. "x400-mts-identifier",    HDR_IGNORE,
  1126. "x400-originator",    HDR_IGNORE,
  1127. "x400-received",    HDR_IGNORE,
  1128. (char *) 0,             HDR_EXTENSIONS};
  1129.  
  1130. #define N_HDRS ((sizeof(hdr_list)/sizeof(CMD_TABLE)) - 1)
  1131.  
  1132. get_hdr (key, field)
  1133. char **key;
  1134. char **field;
  1135. {
  1136.     char *cp;
  1137.     int hval;
  1138.  
  1139. PP_DBG (("get_hdr()"));
  1140.  
  1141.     if (first_hdr)
  1142.     {
  1143.         first_hdr = FALSE;
  1144.         if (fgets (linebuf, LINESIZE - 1, fp_rfc_in) == NULL)
  1145.             return HDR_ERROR;
  1146.         hdrbuflen = LINESIZE;
  1147.         hdrbuf =  malloc (LINESIZE);
  1148.         if (hdrbuf == NULL)
  1149.             return HDR_ERROR;
  1150.     }
  1151.  
  1152.     if (linebuf [0] == '\0')
  1153.         return HDR_EOH;
  1154.  
  1155.     hdrbuf [0] = '\0';
  1156.     strcat (hdrbuf, linebuf);
  1157.     linebuf [0] = '\0';
  1158.  
  1159.     while (!feof (fp_rfc_in))
  1160.     {
  1161.         if ((fgets (linebuf, LINESIZE -1, fp_rfc_in) == NULL)
  1162.                 && !feof (fp_rfc_in))
  1163.             return HDR_ERROR;
  1164.         if (!isspace (linebuf[0]))
  1165.             break;
  1166.                     /* continuation */
  1167.         if ((int)strlen (linebuf) <= 1)
  1168.         {
  1169.             PP_DBG (("Header terminated before EOF"));
  1170.             linebuf [0] = '\0';
  1171.             break;
  1172.         }
  1173.  
  1174.         if (hdrbuflen < (int)strlen (hdrbuf) + (int)strlen (linebuf))
  1175.         {       
  1176.             hdrbuflen = hdrbuflen * 2;
  1177.                     /* linebuf must be shorter */
  1178.             hdrbuf = realloc (hdrbuf, (unsigned int) hdrbuflen);
  1179.             if (hdrbuf == NULL)
  1180.             {
  1181.                 PP_LOG (LLOG_EXCEPTIONS, ("Malloc failed"));
  1182.                 return NOTOK;
  1183.             }
  1184.         }
  1185.         strcat (hdrbuf, linebuf);
  1186.     }
  1187.  
  1188.     if (feof (fp_rfc_in))
  1189.         /* set end of file condition ready for next call */
  1190.         linebuf[0] = '\0';
  1191.     
  1192.     if ((cp = index (hdrbuf, ':')) == NULLCP)
  1193.     {
  1194.         PP_DBG (("Header without key '%s'", hdrbuf));
  1195.         *key = hdrbuf;
  1196.         *field = hdrbuf;
  1197.         return HDR_ERROR;
  1198.     }
  1199.  
  1200.     *cp++ = '\0';
  1201.     *key = hdrbuf;
  1202.     *field = cp;
  1203.     field_tidy (*key);
  1204.  
  1205.  
  1206.     hval = cmdbsrch(*key, hdr_list, N_HDRS);
  1207.     PP_DBG (("Header: '%d' '%s' '%s'", hval,
  1208.         *key,  *field));
  1209.     return hval;
  1210. }
  1211.  
  1212. field_tidy (field)
  1213. char *field;
  1214. {       /* strip newlines, leading/trailing space */
  1215.     register char *p, *q;
  1216.  
  1217.     p = field;
  1218.     q = field;
  1219.  
  1220.  
  1221.     while (isspace(*p))
  1222.         p++;
  1223.  
  1224.     while (*p != '\0')
  1225.         if (*p != '\n')
  1226.             *q++ = *p++;
  1227.         else
  1228.             p++;
  1229.     *q-- = '\0';
  1230.  
  1231.     while (isspace(*q))
  1232.         *q-- = '\0';
  1233. }       
  1234.  
  1235. extern char    *loc_dom_site;
  1236.  
  1237. gen_mid (mid_ptr)               /* generate  random mailid */
  1238. struct type_IOB_IPMIdentifier **mid_ptr;
  1239. {
  1240.         char buf [LINESIZE];
  1241.         long now;
  1242.         (void) time (&now);
  1243.         sprintf (buf, "<\"%ld %s", getpid(), ctime (&now));
  1244.         buf [strlen(buf) - 1] = '\0';
  1245.         strcat (buf, "\"@");
  1246.         strcat (buf, loc_dom_site);
  1247.         strcat (buf, ">");
  1248.         return (hdr_mid (buf, mid_ptr));
  1249. }
  1250.  
  1251. hdr_importance (field, pparm)
  1252. char    *field;
  1253. int    *pparm;
  1254. {
  1255.     compress(field, field);
  1256.     
  1257.     if (lexequ(field, "low") == 0)
  1258.         *pparm = int_IOB_ImportanceField_low;
  1259.     else if (lexequ(field, "normal") == 0)
  1260.         *pparm = int_IOB_ImportanceField_normal;
  1261.     else if (lexequ (field, "high") == 0)
  1262.         *pparm = int_IOB_ImportanceField_high;
  1263.     else
  1264.         return NOTOK;
  1265.     return OK;
  1266. }
  1267.  
  1268. hdr_sensitivity (field, psensitivity)
  1269. char    *field;
  1270. struct type_IOB_SensitivityField    **psensitivity;
  1271. {
  1272.     int    parm;
  1273.  
  1274.     compress(field, field);
  1275.  
  1276.     if (lexequ(field, "personal") == 0)
  1277.         parm = int_IOB_SensitivityField_personal;
  1278.     else if (lexequ(field, "private") == 0)
  1279.         parm = int_IOB_SensitivityField_private;
  1280.     else if (lexequ(field, "company-confidential") == 0)
  1281.         parm = int_IOB_SensitivityField_company__confidential;
  1282.     else
  1283.         return NOTOK;
  1284.  
  1285.     *psensitivity = (struct type_IOB_SensitivityField *) 
  1286.         calloc (1, sizeof(struct type_IOB_SensitivityField));
  1287.     (*psensitivity)->parm = parm;
  1288.     return OK;
  1289. }
  1290.  
  1291. hdr_autoforwarded (field, pauto)
  1292. char    *field;
  1293. struct type_IOB_AutoForwardedField    **pauto;
  1294. {
  1295.     int    parm;
  1296.  
  1297.     compress(field, field);
  1298.  
  1299.     if (lexequ(field, "true") == 0)
  1300.         parm = 1;
  1301.     else if (lexequ(field, "false") == 0)
  1302.         parm =0;
  1303.     else 
  1304.         return NOTOK;
  1305.     
  1306.     *pauto = (struct type_IOB_AutoForwardedField *)
  1307.         calloc(1, sizeof(struct type_IOB_AutoForwardedField));
  1308.     (*pauto)->parm = parm;
  1309.     
  1310.     return OK;
  1311. }
  1312.